package itheima.demo02;

import java.util.zip.DeflaterOutputStream;

public class ArrayUtil {
    //工具类私有化成员构造方法
    private ArrayUtil() {
    }

    //需要定义为静态的
    public static String PrintArr(int[] arr) {
        StringBuilder sb = new StringBuilder();
        sb.append("[");
        for (int i = 0; i < arr.length; i++) {
            //最后一个元素
            if (i == arr.length - 1) {
                sb.append(arr[i]);
            } else {
                sb.append(arr[i]).append(",");
            }
        }
        sb.append("]");
        return sb.toString();
    }

    //求出数组的平均值
    public static double GetAverage(double[] arr) {
        double sum = 0;
        for (int i = 0; i < arr.length; i++) {
            sum = sum + arr[i];
        }
        return sum / arr.length;
    }
}
